<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<jsp:include page="global.jsp"></jsp:include>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>我的项目</title>
<style type="text/css">
.ctl{
	text-decoration: none;
	color: blue;
	margin: auto 7px;
}
.ctl:HOVER{
	text-decoration: underline;
}
</style>
</head>
<body>
	<div class="easyui-layout" style="width:100%;height:648px;">
		<div data-options="region:'north',title:'我负责的项目'" style="height: 340px;">
			<table id="mydg" class="easyui-datagrid" style="height:301px; width:100%;"
					data-options="
						rownumbers:true,
						singleSelect:true,
						pagination:true,
						fitColumns:true,
						toolbar:'#mytb'">
				<thead>
					<tr>
						<th data-options="field:'name',width:80,align:'center'">项目名称</th>
						<th data-options="field:'projectCode',width:80,align:'center'">项目代号</th>
						<th data-options="field:'projectReportFrequencyName',width:60,align:'center'">项目报告频度</th>
						<th data-options="field:'departmentName',width:60,align:'center'">部门</th>
						<th data-options="field:'planFinishDate',width:60,align:'center'">计划完成日期</th>
						<th data-options="field:'actualFinishDate',width:60,align:'center'">实际完成日期</th>
						<th data-options="field:'planConsumeWorkTime',width:40,align:'center'">计划工时</th>
						<th data-options="field:'actualConsumeWorktime',width:40,align:'center'">实际工时</th>
						<th data-options="field:'peopleAverage',width:40,align:'center'">人天数</th>
						<th data-options="field:'status',width:40,align:'center'">状态</th>
						<th data-options="field:'id',width:80,align:'center',formatter:myProjectFormatControl">管理</th>
					</tr>
				</thead>
			</table>
			<div id="mytb" style="padding:5px 5px;">
				项目来源:
				<select data-options="editable: false" id = "projectSource" class="easyui-combobox" style="height:25px;">
					<option value = "-1"> --全部-- </option>
					<c:forEach var="item" items="${projectSources }" >
						<option value = "${item.id }">${item.name }</option>
					</c:forEach>
				</select>
				报告频度:
				<select data-options="editable: false" id = "projectReportFrequency" class="easyui-combobox" style="height:25px;">
					<option value = "-1"> --全部-- </option>
					<c:forEach var="item" items="${projectReportFrequencys }" >
						<option value = "${item.id }">${item.name }</option>
					</c:forEach>
				</select>
				客户:
				<select data-options="editable: false" id = "customer" class="easyui-combobox" style="height:25px;">
					<option value = "-1"> --全部-- </option>
					<c:forEach var="item" items="${customers }" >
						<option value = "${item.id }">${item.name }</option>
					</c:forEach>
				</select>
				项目类型:
				<select data-options="editable: false" id = "projectType" class="easyui-combobox" style="height:25px;">
					<option value = "-1"> --全部-- </option>
					<c:forEach var="item" items="${projectTypes }" >
						<option value = "${item.id }">${item.name }</option>
					</c:forEach>
				</select>
				部门:
				<select data-options="editable: false" id = "department" class="easyui-combobox" style="height:25px;">
					<option value = "-1"> --全部-- </option>
					<c:forEach var="item" items="${departments }" >
						<option value = "${item.id }">${item.name }</option>
					</c:forEach>
				</select>
				状态:
				<select data-options="editable: false" id = "myStatus" class="easyui-combobox" style="height:25px;">
					<option value = ""> --全部-- </option>
					<option value = "0001">未领取</option>
					<option value = "0055">进行中</option>
					<option value = "0200">申请延期</option>
					<option value = "0100">申请完结</option>
					<option value = "3000">审批通过</option>
					<option value = "9000">已完成</option>
				</select>
				项目名称: <input class="easyui-textbox" type="text" id="myProjectName" style="width:200px;height:25px;">
				<a href="javascript:mySearch()" class="easyui-linkbutton" iconCls="icon-search">查 找</a>
			</div>
		</div>
		<div data-options="region:'south',title:'我参与的项目'" style="height: 320px;">
			<table id="havedg" class="easyui-datagrid" style="height:291px; width:100%;"
					data-options="
						rownumbers:true,
						singleSelect:true,
						pagination:true,
						fitColumns:true,
						toolbar:'#havetb'">
				<thead>
					<tr>
						<th data-options="field:'name',width:80,align:'center'">项目名称</th>
						<th data-options="field:'projectCode',width:80,align:'center'">项目代号</th>
						<th data-options="field:'projectReportFrequencyName',width:60,align:'center'">项目报告频度</th>
						<th data-options="field:'departmentName',width:60,align:'center'">部门</th>
						<th data-options="field:'planFinishDate',width:60,align:'center'">计划完成日期</th>
						<th data-options="field:'actualFinishDate',width:60,align:'center'">实际完成日期</th>
						<th data-options="field:'planConsumeWorkTime',width:40,align:'center'">计划工时</th>
						<th data-options="field:'actualConsumeWorktime',width:40,align:'center'">实际工时</th>
						<th data-options="field:'peopleAverage',width:40,align:'center'">人天数</th>
						<th data-options="field:'status',width:40,align:'center'">状态</th>
						<th data-options="field:'id',width:40,align:'center',formatter:formatControl">管理</th>
					</tr>
				</thead>
			</table>
			<div id="havetb" style="padding:5px 5px;">
				项目来源:
				<select data-options="editable: false" id = "haveProjectSource" class="easyui-combobox" style="height: 25px;">
					<option value = "-1"> --全部-- </option>
					<c:forEach var="item" items="${projectSources }" >
						<option value = "${item.id }">${item.name }</option>
					</c:forEach>
				</select>
				报告频度:
				<select data-options="editable: false" id = "haveProjectReportFrequency" class="easyui-combobox" style="height: 25px;">
					<option value = "-1"> --全部-- </option>
					<c:forEach var="item" items="${projectReportFrequencys }" >
						<option value = "${item.id }">${item.name }</option>
					</c:forEach>
				</select>
				客户:
				<select data-options="editable: false" id = "haveCustomer" class="easyui-combobox" style="height: 25px;">
					<option value = "-1"> --全部-- </option>
					<c:forEach var="item" items="${customers }" >
						<option value = "${item.id }">${item.name }</option>
					</c:forEach>
				</select>
				项目类型:
				<select data-options="editable: false" id = "haveProjectType" class="easyui-combobox" style="height: 25px;">
					<option value = "-1"> --全部-- </option>
					<c:forEach var="item" items="${projectTypes }" >
						<option value = "${item.id }">${item.name }</option>
					</c:forEach>
				</select>
				部门:
				<select data-options="editable: false" id = "haveDepartment" class="easyui-combobox" style="height: 25px;">
					<option value = "-1"> --全部-- </option>
					<c:forEach var="item" items="${departments }" >
						<option value = "${item.id }">${item.name }</option>
					</c:forEach>
				</select>
				状态:
				<select data-options="editable: false" id = "haveStatus" class="easyui-combobox" style="height:25px;">
					<option value = ""> --全部-- </option>
					<option value = "0001">未领取</option>
					<option value = "0055">进行中</option>
					<option value = "0200">申请延期</option>
					<option value = "0100">申请完结</option>
					<option value = "3000">审批通过</option>
					<option value = "9000">已完成</option>
				</select>
				项目名称: <input class="easyui-textbox" type="text" id="haveName" style="width:200px;height:25px;">
				<a href="javascript:haveSearch()" class="easyui-linkbutton" iconCls="icon-search">查 找</a>
			</div>
		</div>
	</div>

	<div id="lookDetail" class="easyui-window" title="管理" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:1100px; height:600px;padding:0px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:0px;">
				<iframe id="detail" width="100%" height="100%" frameborder="0"></iframe>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="javascript:$('#lookDetail').window('close');" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<div id="projectApply" class="easyui-window" title="管理" data-options="modal:true,closed:true,iconCls:'icon-search'" style="width:1100px; height:600px;padding:0px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:0px;">
				<iframe id="projectApplyDetail" width="100%" height="100%" frameborder="0"></iframe>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="javascript:$('#projectApply').window('close');$('#mydg').datagrid('reload');" style="width:80px">关 闭</a>
			</div>
		</div>
	</div>
	
	<script type="text/javascript">
		function myProjectFormatControl(val, row){
			var content = "";
			if(row.statusCode == '0001'){
				content += '<a class="ctl" href="javascript:void(0)" onclick="pullDownProject(' + val + ')">领取项目</a>';
			} else if(row.statusCode == '0055'){
				content += '<a class="ctl" href="javascript:void(0)" onclick="projectOrganizationmgr(' + val + ', \'' + row.name + '\')">维护</a>';
				content += '<a class="ctl" href="javascript:void(0)" onclick="projectApplyDelay(' + val + ', \'' + row.name + '\')">延期</a>';
				content += '<a class="ctl" href="javascript:void(0)" onclick="projectApplyFinish(' + val + ', \'' + row.name + '\')">完成</a>';
			} else if(row.statusCode == '0200'){
				content += '<a class="ctl" href="javascript:void(0)" onclick="projectOrganizationmgr(' + val + ', \'' + row.name + '\')">维护</a>';
				content += '<a class="ctl" href="javascript:void(0)" onclick="projectApplyDelay(' + val + ', \'' + row.name + '\')">查看延期</a>';
			} else if(row.statusCode == '0100') {
				content += '<a class="ctl" href="javascript:void(0)" onclick="projectApplyFinish(' + val + ', \'' + row.name + '\')">完结审批进度</a>';
			}  else if(row.statusCode == '9000') {
				content += '<a class="ctl" href="javascript:void(0)" onclick="lookProjectDetail(' + val + ', \'' + row.name + '\')">查看项目信息</a>';
			}
			return content;
		}
		function formatControl(val, row){
			return '<a class="ctl" href="javascript:void(0)" onclick="projectPlanReport(' + val + ', \'' + row.name + '\')">查看进度</a>';
		}
		function mySearch(){
			var name = $("#myProjectName").textbox("getValue").trim();
			var projectSource = $("#projectSource").combobox("getValue");
			var projectReportFrequency = $("#projectReportFrequency").combobox("getValue").trim();
			var customer = $("#customer").combobox("getValue").trim();
			var projectType = $("#projectType").combobox("getValue").trim();
			var department = $("#department").combobox("getValue").trim();
			var myStatus = $("#myStatus").combobox("getValue").trim();
			var url = "queryMyProjects?sort=project.status&order=asc&personId=${currentUser.id}&projectMemberTypeId=10&projectSourceId=" + projectSource + "&customerId=" + customer + "&projectReportFrequencyId=" + projectReportFrequency + "&projectTypeId=" + projectType + "&departmentId=" + department + "&projectName=" + name + "&status=" + myStatus;
			$("#mydg").datagrid('reload', url);
		}
		function haveSearch(){
			var name = $("#haveName").textbox("getValue").trim();
			var projectSource = $("#haveProjectSource").textbox("getValue").trim();
			var projectReportFrequency = $("#haveProjectReportFrequency").textbox("getValue").trim();
			var customer = $("#haveCustomer").textbox("getValue").trim();
			var projectType = $("#haveProjectType").textbox("getValue").trim();
			var department = $("#haveDepartment").combobox("getValue").trim();
			var haveStatus = $("#haveStatus").textbox("getValue").trim();
			var url = "queryMyProjects?sort=project.status&order=asc&personId=${currentUser.id}&projectMemberTypeId=5&projectSourceId=" + projectSource + "&customerId=" + customer + "&projectReportFrequencyId=" + projectReportFrequency + "&projectTypeId=" + projectType + "&departmentId=" + department + "&projectName=" + name + "&status=" + haveStatus;
			$("#havedg").datagrid('reload', url);
		}
		
		function lookProjectDetail(id, name){
			var url = "lookProjectDetail?id=" + id;
			$("#detail").attr("src", url);
			$('#lookDetail').window({title: "查看我的项目“" + name + "”的信息"});
			$('#lookDetail').window('open');
		}
		
		function projectOrganizationmgr(id, name){
			var url = "projectOrganizationmgr?id=" + id;
			$("#detail").attr("src", url);
			$('#lookDetail').window({title: "维护我的项目“" + name + "”信息"});
			$('#lookDetail').window('open');
		}
		function projectApplyDelay(id, name){
			var url = "projectDelayApplymgr?projectId=" + id;
			$("#projectApplyDetail").attr("src", url);
			$('#projectApply').window({title: "我的项目“" + name + "”申请延期"});
			$('#projectApply').window('open');
		}
		function projectApplyFinish(id, name){
			var url = "projectFinishApplymgr?projectId=" + id;
			$("#projectApplyDetail").attr("src", url);
			$('#projectApply').window({title: "我的项目“" + name + "”申请完结历史"});
			$('#projectApply').window('open');
		}
		
		function projectPlanReport(id, name){
			var url = "projectPlanReport?id=" + id;
			$("#detail").attr("src", url);
			$('#lookDetail').window({title: "我参与的项目“" + name + "”情况"});
			$('#lookDetail').window('open');
		}
		
		function pullDownProject(id){
			data = "id=" + id + "&status=0055";
			$.ajax({
			  type: "POST",
			  url: "pullDownProject",
			  data: data,
			  success:function(data){
				  	var val = $.parseJSON(data);
					if(val.success){
						bottomRight('提示', '领取成功！');
						$('#mydg').datagrid('reload');
					}else{
						$.messager.alert("提示", val.msg, "error");
					}
			  }
			});
		}
		
		$(function(){
			mySearch();
			haveSearch();
		});
	</script>
	
</body>
</html>